import { createSlice } from '@reduxjs/toolkit'

const userSlice = createSlice({
  name: 'user',
  initialState: {
    token: localStorage.getItem('token'),
    // 其他用户信息
  },
  reducers: {
    setToken(state, action) {
      let token = action.payload
      state.token = token
      if(token)  {
        localStorage.setItem('token', action.payload)
      } else {
        localStorage.removeItem('token')
      }
    },
  }
})

export const { setToken } = userSlice.actions
export default userSlice.reducer
